package com.yuejie.musicai.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yuejie.musicai.beans.Info;
import com.yuejie.musicai.services.impl.AccountServiceImpl;

/**
 * 用户账号相关Controller
 * @author Ocelot
 *
 */
@Controller
public class AccountController {
	
	@Autowired
	AccountServiceImpl  accountservice;
	
	private static final Logger logger = LoggerFactory.getLogger(AccountController.class);

	/**
	 * 返回注册页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/account/apply")
	public String apply(Model model) {
		return "account/apply";
	}
	
	/**
	 * 返回登录页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/account/login")
	public String login(Model model) {
		return "account/login";
	}
	
	/**
	 * 执行注册
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/account/doapply", method=RequestMethod.GET)
	public @ResponseBody Info doapply(@RequestParam String user, @RequestParam String password) {
		return accountservice.creatuser(user, password);
	}
	
	/**
	 * 执行登录
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/account/dologin", method=RequestMethod.GET)
	public @ResponseBody Info dologin(@RequestParam String user, @RequestParam String password) {
		return accountservice.login(user, password);
	}
	
	/**
	 * 退出
	 */
	@RequestMapping(value="/account/logout",method=RequestMethod.GET)
	public @ResponseBody Info doLogout(){
		Info info = new Info();
		info.setMessage("success");
		return info;
	}
	
}
